var baseData={
	phone:'',
	CourseTypeList:[],
	isCode:false,
	userType:1
}
// 分类
$('.classify').on('mouseover',function () {
    $('.category-f').show()
})
$('.classify').on('mouseout',function () {
    $('.category-f').hide()
})
var index = $(".cate-detail").length;
for(var i=0;i<index;i++){
    $(".cate-detail").eq(i).on("mouseover",function () {
        $(this).find('.list-item').show().parent().siblings().find('.list-item').hide()
    });
}
// 登录后用户功能
$('.has-login').on('mouseover',function () {
    $('.personal-fun').show()
})

$('.has-login').on('mouseout',function () {
    $('.personal-fun').hide()
})

// 登录界面开关
$('.login').on('click',function (e) {
    e.stopPropagation();
    $("#login-box").show();
    $(".login-in").show();
    $('.login-main').show().siblings().hide()
    $(".full-shade").show()
})
function showOnly(elem) {
    elem.show().siblings().hide();
}
$(".next-btn-f").on('click',function () {
    showOnly($(".by-phone"))
});
//验证手机号
$(".next-tel").on('click',function () {
	var disabled=$(".next-tel").attr('disabled');
	console.log(disabled)
	if(disabled){
		return;
	}else{
		var phoneNum=$('.user-tel').val();
		baseData.phone=phoneNum;
    if(isEmpty(phoneNum)){
      alert('手机号不能为空！');
      return; 
    }
		$('.send-phone').text(phoneNum)
		var data={
			username:phoneNum
		};
		judgeMobile(data,function(res){
			if(res.code==0){
				//已经注册可登陆
				if(baseData.isCode){
					//手机验证码登陆
					showOnly($(".re-password-code-login"))
				}else{
					showOnly($(".re-password-login"))
				}
				
			}else if(res.code==1){
				 // showOnly($(".f-by-phone"))
				 showOnly($(".re-password-t"))
			}
		})
	}
	
    
});
//注册
$('.next-tel-fo').on('click',function(){
	var password=$('.new-password').val();
  if(isEmpty(password)){
    alert('密码不能为空！');
    return; 
  }
	var data={
		password:password,
		username:baseData.phone,
		type:baseData.userType
	}
	register(data,function(res){
		if(res.code==0){
			showOnly($(".set-success"))
			if(baseData.userType==1){
				window.location.href='renzhengcenter.html'
			}
		}else{
			alert(res.msg);
		}
		
	})
})
//账号密码登陆
$('.next-tel-login').on('click',function(){
	var password=$('.new-password').val();
	var data={
		password:password,
		username:baseData.phone,
		type:1
	}
	login(data,function(res){
		if(res.code==0){
			//登陆成功！
			$(".set-perfer").hide();
			$(".login-box").hide();
			$('.has-login').css('display','block');
			$('.user-lr').css('display','none');
			getInfo(function(res){
				console.log(res)
			})
		}else{
			alert(res.msg);
		}
	})
})
//发送验证码
$('.send-vari').on('click',function(){
	var phone=baseData.phone;
	var data={
		phone:phone
	}
	getCaptcha(data,function(res){
		console.log(res)
		if(res.code==0){
			
		}else{
			alert(res.msg)
		}
	})
})
//验证码登陆
$('.fast-login').on('click',function(){
	showOnly($(".by-phone"));
	baseData.isCode=true;
})
//验证码验证登陆
$('.next-tel-code').on('click',function(){
	var phone=baseData.phone;
	var codes = $('.veri-code').val();
	if(isEmpty(code)){
    alert('请输入二维码！');
    return; 
  }
	var data={
		captcha:codes,
		phone:phone
	}
	verifyCaptcha(data,function(res){
		if(res.code==0){
			var loginData={
				username:phone,
				device:'web',
			}
			loginCode(loginData,function(rs){
				if(rs.code==0){
					//登陆成功！
					$(".set-perfer").hide();
					$(".login-box").hide();
					$('.has-login').css('display','block');
					$('.user-lr').css('display','none');
				}else{
					alert(rs.msg);
				}
			})
		}else{
			alert(res.msg);
		}
	})
})
$(".next-tel-s").on('click',function () {
    showOnly($(".re-password"));
});

$(".next-tel-t").on('click',function () {
    showOnly($(".re-password-s"))
})

$(".next-tel-f").on('click',function () {
    showOnly($(".re-password-t"))
})

$(".enter").on("click",function () {
    $("#login-in").hide();
    $(".set-perfer").show();
})
$(".close-btn").on("click",function (e) {
    e.stopPropagation();
    $("#login-box").hide()
})

// 手机号正则
$('.user-tel').blur(function () {
    var reg = /^([1][358][0-9][0-9]{8})|([1][4][37][0-9]{8})|([1][7][01367][0-9]{8})/;
    if(reg.test($(this).val())){
        $(this).parent().css('border','1px solid green')
        $(".next-tel").attr('disabled',false)
    }else{
        $(this).parent().css('border','1px solid red')
        $(".next-tel").attr('disabled','disabled')
    }
})

// 搜索

$(".icon-search").on('click',function () {
    $(".search-box").show();
    $(".main-nav").hide();
});


$(".close-search").on('click',function () {
    $(".search-box").hide();
    $(".main-nav").show();
})

// 退出登录
$(".login-out").on('click',function () {
    $(".has-login").hide();
    $(".user-lr").show()
})

//获取一级和二级分类-首次登陆使用
getIndexCourseTypeList(function(res){
    if(res.code==0){
        var data=res.data;
		baseData.CourseTypeList=data;
        for(var i in data){
            var list=data[i].list;
			var cate_title=data[i].name;
			var perfer_item=''
			var color='';
            for(var j in list){	
			 perfer_item=perfer_item+'<li class="perfer-item">'+list[j].name+'</li>'
            }
			switch (i%4){
				case 0:
					color='blu';
					break;
				case 1:
					color='yel';
					break;
				case 2:
					color='gre';
					break;
				case 3:
					color='red';
					break;			
				default:
					break;
			}
			var perfer_cate='<div class="perfer-cate '+color+'">'+
           '<p class="p-cate-title">'+data[i].name+'</p>'+
            '<ul class="perfer-list">'+perfer_item+
			'</ul>'+
			'</div> ';
			$('.set-perfer').append(perfer_cate)
        }
        $('.set-perfer').append('<a href="javascript:;" class="save-perfer layui-btn">保存</a>')
    }else{
        
    }
})
$(".save-perfer").on("click",function () {
    $(".set-perfer").hide();
    $(".login-box").hide();
})
//教师端
$('.identity').on('click',function(){
	window.location.href='renzhengcenterstep.html'
})
//选择学生
$('.i-student').on("click",function(){
	baseData.userType=0;
})

$('.i-teacher').on("click",function(){
	baseData.userType=1;
})
// 身份选择
$(".i-chice").on('click',function () {
	$(this).addClass('i-choose').siblings().removeClass('i-choose')
})
//获取个认信息

//判断是否为空
function isEmpty(str) {
    if (typeof (str) == 'undefined' || str == 'undefined' || str == '' || str == false || str == '') {
      return true;
    }
    else return false;
  }
